package com.openbravo.data.gui;

import com.openbravo.basic.BasicException;
import com.openbravo.data.loader.LocalRes;
import com.openbravo.data.user.BrowsableEditableData;
import com.openbravo.data.user.BrowseListener;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Rectangle;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.ListCellRenderer;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class JListNavigator extends JPanel
  implements BrowseListener, ListSelectionListener
{
  protected BrowsableEditableData m_bd;
  private JScrollPane jScrollPane1;
  private JList m_jlist;

  public JListNavigator(BrowsableEditableData paramBrowsableEditableData)
  {
    this(paramBrowsableEditableData, false);
  }

  public JListNavigator(BrowsableEditableData paramBrowsableEditableData, boolean paramBoolean)
  {
    this.m_bd = paramBrowsableEditableData;
    initComponents();
    if (paramBoolean)
    {
      this.jScrollPane1.getVerticalScrollBar().setPreferredSize(new Dimension(35, 35));
      this.jScrollPane1.setHorizontalScrollBarPolicy(31);
      this.jScrollPane1.setVerticalScrollBarPolicy(22);
    }
    this.m_jlist.addListSelectionListener(this);
    this.m_jlist.setModel(this.m_bd.getListModel());
    this.m_bd.addBrowseListener(this);
  }

  public void setCellRenderer(ListCellRenderer paramListCellRenderer)
  {
    this.m_jlist.setCellRenderer(paramListCellRenderer);
  }

  public void updateIndex(int paramInt1, int paramInt2)
  {
    if ((paramInt1 >= 0) && (paramInt1 < paramInt2))
      this.m_jlist.setSelectedIndex(paramInt1);
    else
      this.m_jlist.setSelectedIndex(-1);
  }

  public void valueChanged(ListSelectionEvent paramListSelectionEvent)
  {
    if (!paramListSelectionEvent.getValueIsAdjusting())
    {
      int i = this.m_jlist.getSelectedIndex();
      if (i >= 0)
      {
        if (!this.m_bd.isAdjusting())
          try
          {
            this.m_bd.moveTo(i);
          }
          catch (BasicException localBasicException)
          {
            MessageInf localMessageInf = new MessageInf(-67108864, LocalRes.getIntString("message.nomove"), localBasicException);
            localMessageInf.show(this);
          }
        Rectangle localRectangle = this.m_jlist.getCellBounds(i, i);
        this.m_jlist.scrollRectToVisible(localRectangle);
      }
    }
  }

  private void initComponents()
  {
    this.jScrollPane1 = new JScrollPane();
    this.m_jlist = new JList();
    setLayout(new BorderLayout());
    setPreferredSize(new Dimension(200, 2));
    this.m_jlist.setSelectionMode(0);
    this.m_jlist.setFocusable(false);
    this.m_jlist.setRequestFocusEnabled(false);
    this.jScrollPane1.setViewportView(this.m_jlist);
    add(this.jScrollPane1, "Center");
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.data.gui.JListNavigator
 * JD-Core Version:    0.6.0
 */